/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import java.io.*;
import java.net.*;
import java.text.*;
import java.util.Date.*;
import java.util.Calendar;
import java.util.Date;

import javax.servlet.*;
import javax.servlet.http.*;

/**
 *
 * @author Derek
 */
public class SavePostToDBServlet extends HttpServlet {
   
    /** 
    * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
    * @param request servlet request
    * @param response servl et response
    */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        String messageReply = request.getParameter("messageReply");
        
        //long timeInMillis = System.currentTimeMillis();
        //Calendar c = Calendar.getInstance();
        //c.setTime(timeInMillis);
        //Date d = c.getTime();
        Date now = new Date(System.currentTimeMillis()); 
        //SimpleDateFormat sdf = new SimpleDateFormat("dd-mm-yyyy HH:mm:ss a"); //MMMMM.
        SimpleDateFormat sdf = new SimpleDateFormat("kk:mm:ss, d MMM yyyy"); //MMMMM.
        String formattedDateString = sdf.format(now);


        
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
           
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet PostServlet</title>");  
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet PostServlet at " + request.getContextPath () + "</h1>");
            out.println("<p> got reply message : </p>");
            out.println(messageReply);
            out.println("<p> we just need to get the \"replyer\"'s email address </p>");
            out.println("<p> and the time stamp like this : " +  formattedDateString.toString() + "</p>");
            out.println("</body>");
            out.println("</html>");
           
        } finally { 
            out.close();
        }
    } 

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
    * Handles the HTTP <code>GET</code> method.
    * @param request servlet request
    * @param response servlet response
    */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    } 

    /** 
    * Handles the HTTP <code>POST</code> method.
    * @param request servlet request
    * @param response servlet response
    */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
    * Returns a short description of the servlet.
    */
    public String getServletInfo() {
        return "Short description";
    }
    // </editor-fold>
}
